---
title: Spec - howl.log
tags: spec
---
<div class="spec-group spec-group-1">

<h1 id="howl.log">howl.log</h1>

<pre class="highlight moonscript"><code><span class="n">after_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">log</span><span class="p">.</span><span class="n">clear</span><span class="o">!</span><span class="w">
  </span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span></code></pre>


<h4 id="is-exported-globally-as-`log`">is exported globally as `log`</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="nb">type</span><span class="p">(</span><span class="n">_G</span><span class="p">.</span><span class="n">log</span><span class="p">),</span><span class="w"> </span><span class="s1">'table'</span></code></pre>


<h4 id="warn()-is-the-same-as-warning()">warn() is the same as warning()</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">log</span><span class="p">.</span><span class="n">warn</span><span class="p">,</span><span class="w"> </span><span class="n">log</span><span class="p">.</span><span class="n">warning</span></code></pre>

<div class="spec-group spec-group-4">

<h3 id="(when-howl.app.window-is-available-and-showing)">(when howl.app.window is available and showing)</h3>

<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">method</span><span class="w">

</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">method</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">true</span><span class="w">
  </span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">visible:</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w"> </span><span class="ss">command_line:</span><span class="w"> </span><span class="p">{},</span><span class="w"> </span><span class="ss">status:</span><span class="w"> </span><span class="p">[</span><span class="n">m</span><span class="p">]:</span><span class="w"> </span><span class="n">method</span><span class="w">

</span><span class="n">after_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span></code></pre>


<h4 id="sends-the-message-to-howl.app.window.status\\'-..-m-..-'()-if-available">sends the message to howl.app.window.status\\' .. m .. '() if available</h4>

<pre class="highlight moonscript"><code><span class="n">log</span><span class="p">[</span><span class="n">m</span><span class="p">]</span><span class="w"> </span><span class="s1">'message'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">method</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called_with</span><span class="w"> </span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="p">.</span><span class="n">status</span><span class="p">),</span><span class="w"> </span><span class="s1">'message'</span></code></pre>


<h4 id="only-propagates-the-first-line-of-the-message">only propagates the first line of the message</h4>

<pre class="highlight moonscript"><code><span class="n">log</span><span class="p">[</span><span class="n">m</span><span class="p">]</span><span class="w"> </span><span class="s1">'message\nline2\nline3'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">method</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called_with</span><span class="w"> </span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="p">.</span><span class="n">status</span><span class="p">),</span><span class="w"> </span><span class="s1">'message'</span></code></pre>


<h4 id="removes-any-location-info-before-propagating">removes any location info before propagating</h4>

<pre class="highlight moonscript"><code><span class="n">log</span><span class="p">[</span><span class="n">m</span><span class="p">]</span><span class="w"> </span><span class="s1">'[string "../foo/bar.lua"]:32: juicy bit'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">method</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called_with</span><span class="w"> </span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="p">.</span><span class="n">status</span><span class="p">),</span><span class="w"> </span><span class="s1">'juicy bit'</span></code></pre>

</div>
<div class="spec-group spec-group-4">

<h3 id="(when-howl.app.window-is-available-and-showing)">(when howl.app.window is available and showing)</h3>

<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">method</span><span class="w">

</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">method</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">true</span><span class="w">
  </span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">visible:</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w"> </span><span class="ss">command_line:</span><span class="w"> </span><span class="p">{},</span><span class="w"> </span><span class="ss">status:</span><span class="w"> </span><span class="p">[</span><span class="n">m</span><span class="p">]:</span><span class="w"> </span><span class="n">method</span><span class="w">

</span><span class="n">after_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span></code></pre>


<h4 id="sends-the-message-to-howl.app.window.status\\'-..-m-..-'()-if-available">sends the message to howl.app.window.status\\' .. m .. '() if available</h4>

<pre class="highlight moonscript"><code><span class="n">log</span><span class="p">[</span><span class="n">m</span><span class="p">]</span><span class="w"> </span><span class="s1">'message'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">method</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called_with</span><span class="w"> </span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="p">.</span><span class="n">status</span><span class="p">),</span><span class="w"> </span><span class="s1">'message'</span></code></pre>


<h4 id="only-propagates-the-first-line-of-the-message">only propagates the first line of the message</h4>

<pre class="highlight moonscript"><code><span class="n">log</span><span class="p">[</span><span class="n">m</span><span class="p">]</span><span class="w"> </span><span class="s1">'message\nline2\nline3'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">method</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called_with</span><span class="w"> </span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="p">.</span><span class="n">status</span><span class="p">),</span><span class="w"> </span><span class="s1">'message'</span></code></pre>


<h4 id="removes-any-location-info-before-propagating">removes any location info before propagating</h4>

<pre class="highlight moonscript"><code><span class="n">log</span><span class="p">[</span><span class="n">m</span><span class="p">]</span><span class="w"> </span><span class="s1">'[string "../foo/bar.lua"]:32: juicy bit'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">method</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called_with</span><span class="w"> </span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="p">.</span><span class="n">status</span><span class="p">),</span><span class="w"> </span><span class="s1">'juicy bit'</span></code></pre>

</div>
<div class="spec-group spec-group-4">

<h3 id="(when-howl.app.window-is-available-and-showing)">(when howl.app.window is available and showing)</h3>

<pre class="highlight moonscript"><code><span class="kd">local</span><span class="w"> </span><span class="n">method</span><span class="w">

</span><span class="n">before_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">method</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">spy</span><span class="p">.</span><span class="n">new</span><span class="w"> </span><span class="o">-&gt;</span><span class="w"> </span><span class="kc">true</span><span class="w">
  </span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="ss">visible:</span><span class="w"> </span><span class="kc">true</span><span class="p">,</span><span class="w"> </span><span class="ss">command_line:</span><span class="w"> </span><span class="p">{},</span><span class="w"> </span><span class="ss">status:</span><span class="w"> </span><span class="p">[</span><span class="n">m</span><span class="p">]:</span><span class="w"> </span><span class="n">method</span><span class="w">

</span><span class="n">after_each</span><span class="w"> </span><span class="o">-&gt;</span><span class="w">
  </span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="kc">nil</span></code></pre>


<h4 id="sends-the-message-to-howl.app.window.status\\'-..-m-..-'()-if-available">sends the message to howl.app.window.status\\' .. m .. '() if available</h4>

<pre class="highlight moonscript"><code><span class="n">log</span><span class="p">[</span><span class="n">m</span><span class="p">]</span><span class="w"> </span><span class="s1">'message'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">method</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called_with</span><span class="w"> </span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="p">.</span><span class="n">status</span><span class="p">),</span><span class="w"> </span><span class="s1">'message'</span></code></pre>


<h4 id="only-propagates-the-first-line-of-the-message">only propagates the first line of the message</h4>

<pre class="highlight moonscript"><code><span class="n">log</span><span class="p">[</span><span class="n">m</span><span class="p">]</span><span class="w"> </span><span class="s1">'message\nline2\nline3'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">method</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called_with</span><span class="w"> </span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="p">.</span><span class="n">status</span><span class="p">),</span><span class="w"> </span><span class="s1">'message'</span></code></pre>


<h4 id="removes-any-location-info-before-propagating">removes any location info before propagating</h4>

<pre class="highlight moonscript"><code><span class="n">log</span><span class="p">[</span><span class="n">m</span><span class="p">]</span><span class="w"> </span><span class="s1">'[string "../foo/bar.lua"]:32: juicy bit'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">spy</span><span class="p">(</span><span class="n">method</span><span class="p">).</span><span class="n">was</span><span class="p">.</span><span class="n">called_with</span><span class="w"> </span><span class="n">match</span><span class="p">.</span><span class="n">is_ref</span><span class="p">(</span><span class="n">app</span><span class="p">.</span><span class="n">window</span><span class="p">.</span><span class="n">status</span><span class="p">),</span><span class="w"> </span><span class="s1">'juicy bit'</span></code></pre>

</div>
<div class="spec-group spec-group-2">

<h2 id="book-keeping">book keeping</h2>

<h4 id=".entries-is-a-list-of-the-last-log-entries">.entries is a list of the last log entries</h4>

<pre class="highlight moonscript"><code><span class="n">log</span><span class="p">.</span><span class="n">error</span><span class="w"> </span><span class="s1">'my error'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="o">#</span><span class="n">log</span><span class="p">.</span><span class="n">entries</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">log</span><span class="p">.</span><span class="n">entries</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="ss">message:</span><span class="w"> </span><span class="s1">'my error'</span><span class="w">
  </span><span class="ss">level:</span><span class="w"> </span><span class="s1">'error'</span><span class="w">
</span><span class="p">}</span></code></pre>


<h4 id=".last_error-points-to-the-last-error-logged">.last_error points to the last error logged</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">is_nil</span><span class="w"> </span><span class="n">log</span><span class="p">.</span><span class="n">last_error</span><span class="w">
</span><span class="n">log</span><span class="p">.</span><span class="n">error</span><span class="w"> </span><span class="s1">'foo'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'foo'</span><span class="p">,</span><span class="w"> </span><span class="n">log</span><span class="p">.</span><span class="n">last_error</span><span class="p">.</span><span class="n">message</span><span class="w">
</span><span class="n">log</span><span class="p">.</span><span class="n">error</span><span class="w"> </span><span class="s1">'bar'</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="s1">'bar'</span><span class="p">,</span><span class="w"> </span><span class="n">log</span><span class="p">.</span><span class="n">last_error</span><span class="p">.</span><span class="n">message</span></code></pre>


<h4 id="defines-a-&quot;max_log_entries&quot;-config-variable,-defaulting-to-1000">defines a &quot;max_log_entries&quot; config variable, defaulting to 1000</h4>

<pre class="highlight moonscript"><code><span class="n">assert</span><span class="p">.</span><span class="n">not_nil</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">definitions</span><span class="p">.</span><span class="n">max_log_entries</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">max_log_entries</span><span class="p">,</span><span class="w"> </span><span class="mi">1000</span></code></pre>


<h4 id="retains-at-most-&lt;max_log_entries&gt;-of-the-last-entries">retains at most &lt;max_log_entries&gt; of the last entries</h4>

<pre class="highlight moonscript"><code><span class="n">config</span><span class="p">.</span><span class="n">max_log_entries</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="k">for</span><span class="w"> </span><span class="n">i</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="mi">10</span><span class="w">
  </span><span class="n">log</span><span class="p">.</span><span class="n">error</span><span class="w"> </span><span class="s1">'my error '</span><span class="w"> </span><span class="o">..</span><span class="w"> </span><span class="n">i</span><span class="w">

</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="o">#</span><span class="n">log</span><span class="p">.</span><span class="n">entries</span><span class="p">,</span><span class="w"> </span><span class="mi">1</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">same</span><span class="w"> </span><span class="n">log</span><span class="p">.</span><span class="n">entries</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span><span class="w"> </span><span class="p">{</span><span class="w">
  </span><span class="ss">message:</span><span class="w"> </span><span class="s1">'my error 10'</span><span class="w">
  </span><span class="ss">level:</span><span class="w"> </span><span class="s1">'error'</span><span class="w">
</span><span class="p">}</span></code></pre>


<h4 id=".clear()-clears-all-log-entries">.clear() clears all log entries</h4>

<pre class="highlight moonscript"><code><span class="n">log</span><span class="p">.</span><span class="n">error</span><span class="w"> </span><span class="s1">'my error'</span><span class="w">
</span><span class="n">log</span><span class="p">.</span><span class="n">clear</span><span class="o">!</span><span class="w">
</span><span class="n">assert</span><span class="p">.</span><span class="n">equal</span><span class="w"> </span><span class="o">#</span><span class="n">log</span><span class="p">.</span><span class="n">entries</span><span class="p">,</span><span class="w"> </span><span class="mi">0</span></code></pre>

</div>
</div>
